package com.lxc.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lxc.entity.Authors;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AuthorMapper extends BaseMapper<Authors> {

    /*@Select("select a.name,a.picture,a.introduction,w.name,w.work_picture from authors a " +
            "left join works w on a.name =w.author_name where a.id=#{id}")*/
    @Select("select a.name,a.introduction,a.picture  from authors a where id=#{id}")
    @Results({
           /* @Result(column = "id", property = "id"),*/
            @Result(column = "name", property = "name"),
            @Result(column = "name", property = "works", javaType = List.class,
                    many = @Many(select = "com.lxc.mapper.WorkMapper.getWorkByAuthorName")),
            @Result(column = "introduction", property = "introduction"),
            @Result(column = "picture", property = "picture")
    })
    Authors getById(Integer id);

//    @Select("select * from authors")
    List<Authors> getAllAuthors(Integer pageNum,Integer pageSize);
}